/**
 * BatteryChargeLogJob.java
 * Created at 2017-12-12
 * Created by zhanghailin
 * Copyright (C) 2017 BROADTEXT SOFTWARE, All rights reserved.
 */
package com.broadtext.rms.timetask.job;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.broadtext.common.exp.ServiceException;
import com.broadtext.common.utils.DateUtils;
import com.broadtext.rms.timetask.service.ICustomAlertTaskService;

/**
 * <p>ClassName: BatteryChargeLogJob</p>
 * <p>Description: TODO</p>
 * <p>Author: zhanghailin</p>
 * <p>Date: 2017-12-12</p>
 */
public class BatteryChargeLogJob {
    
    /**
     * 日志
     */
    private static Logger logger = LoggerFactory.getLogger(BatteryChargeLogJob.class);
    
    /**
     * 电池监控服务类
     */
    @Autowired
    @Qualifier("customAlertTaskService")
    private ICustomAlertTaskService customAlertTaskService;
    
    /**
     * 
     * <p>Description: 定时任务targetMethod</p>
     */
    public void execute() {
        logger.info("begin insert battery charge log data!");
        try {
            //结转数据时间，每天早上08:30:00结转前一天早上08:00:00点到今天早上07:59:59的数据
            SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
            String gatherTimeStart = f.format(DateUtils.getYesterdayStart())+" 08:00:00";
            String gatherTimeEnd = f.format(new Date())+" 07:59:59";
            //String gatherTimeStart = DateUtils.getYesterdayStartStr();
            //String gatherTimeEnd = DateUtils.getYesterdayEndStr();
            String dayBeforeYesterdayS = DateUtils.getDayBeforeYesterdayStartStr();
            String dayBeforeYesterdayE = DateUtils.getDayBeforeYesterdayEndStr();
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("gatherTimeStart", gatherTimeStart);
            map.put("gatherTimeEnd", gatherTimeEnd);
            map.put("dayBeforeYesterdayS", dayBeforeYesterdayS);
            map.put("dayBeforeYesterdayE", dayBeforeYesterdayE);
            this.customAlertTaskService.createBatteryChargeData(map);
        } catch (ServiceException e) {
            e.printStackTrace();
            logger.info("insert battery charge log data error!");
        } catch (ParseException e1) {
            e1.printStackTrace();
            logger.info("insert battery charge log data error!");
        }
        logger.info("end insert battery charge log data!");
    }
    

}
